//index.js
//获取应用实例
const app = getApp()
console.log("index.js--app.globalData:%o",app.globalData)




Page({
	data: {
    motto: 'Hello World',
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
		testArray: [{ text1: 'init data01' }],
		testObject: {
			text1: 'init data001'
		},
		imgFilePath:'',
    uploadedPictures: [
      'http://chuantu.xyz/t6/702/1568604200x3661913030.png',
      'http://chuantu.xyz/t6/702/1568604591x3703728804.png',
      'http://chuantu.xyz/t6/702/1568604868x3703728804.png',
    ],
    
  },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../second/second?name=dongpenffei&sex=male'
    })

    /*
		wx.switchTab({
			url: '../logs/logs?name=dongpenffei&sex=male',
		})
		*/
  },
	bindMottoTap: function() {
		this.setData({
			motto: '座右铭--有家才有远方'
		})
	},
	changeItemInArray: function (event) {
		// you can use this way to modify a danamic data path 
		console.log(event.currentTarget.dataset.goodsName)



		//方法一:
		this.setData({
			'testArray[0].text1':'changed data01'
		})


		//方法二：当下标是变量时需用这种
		/*
		var index = 0;
		var key = 'testArray[' + index + '].text1'
		this.setData({
			[key]: 'changed data01'
		})
		*/

	}, 
	scanCodeAction: function() {
		wx.scanCode({
			success: (res) => {
				console.log("扫码结果：\n %o", res)
			}
		})
	},
	WebRequestAction: function() {
		//请求1
		wx.request({
			url: 'https://b.tingzhijun.com/v1/gateway.htm', //接口地址
			method: "POST",
			data: {
				sign: 'c185f063d8ebc4e899ee0f8ec67ca512',
				msg: '{\"appId\":\"rwmmoa1495442077210\",\"password\":\"3e01524af96412c5e94275a0ec763580\",\"method\":\"cashier.login\",\"mobile\":\"13523448667\"}'
			},
			header: {
				'content-type': 'application/x-www-form-urlencoded' // 默认值为 application/json
			},
			success: function (res) {
				console.log("接口请求返回的数据： \n%o", res.data)
        wx.showModal({
          title: '接口返回数据',
          content: '',
        })
			}
		})
	},
	interactiveFeedbackTest: function() {
		//展示toast
		/*
		wx.showToast({
			title: '哈哈成功了哈哈成功了',
			icon: 'none',
			image: '',
			duration: 2000,
			mask: true,
			success: function (res) {
				
			},
			fail: function (res) { },
			complete: function (res) {
				
			},
		})
		*/

		//展示Loading
		/*
		wx.showLoading({
			title: '加载中',
		})
		setTimeout(function () {
			wx.hideLoading()
		}, 2000)
		*/

		//显示模态弹窗
		
		wx.showModal({
			title: '提示',
			content: '这是一个模态弹窗',
			success: function (res) {
				if (res.confirm) {
					console.log('用户点击确定')
				} else if (res.cancel) {
					console.log('用户点击取消')
				}
			}
		})
		
    /*
		//显示ActionSheet
		var items = ["教师", "医生", "程序员"]
		wx.showActionSheet({
			itemList: items,
			itemColor: '',
			success: function(res) {
				console.log(res.tapIndex + "  " + items[res.tapIndex])
			},
			fail: function(res) {
				console.log("ActionSheet 取消")
			},
			complete: function(res) {},
		})
    */
	},
	getCurrentLocation: function () {
		wx.getLocation({
			type: 'wps84',
			success: function(res) {
				var latitude = res.latitude // 经度
				var longitude = res.longitude // 纬度
				console.log("经度:"+longitude+";纬度:"+latitude)
			},
			fail: function(res) {},
			complete: function(res) {},
		})
	},
  openLocation: function () {
    wx.openLocation({
      latitude: 34.746551,
      longitude: 113.625587,
      scale: 18,
      name: "董鹏飞的家"
    })
  },
  chooseLocation: function () {
    wx.chooseLocation({
      success: function(res) {
        wx.showModal({
          title: res.name,
          content: res.address,
        })
      },
    })
  },
	chooseAlumnImageOrCamera: function() {
		var that = this
		wx.chooseImage({
			count: 1, // 默认9
			sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
			sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
			success: function(res) {
				// 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
				var tempFilePaths = res.tempFilePaths
				console.log("图片路径--> " + tempFilePaths[0])
				that.setData({
					imgFilePath: tempFilePaths[0]
				})
			},
			fail: function(res) {},
			complete: function(res) {},
		})
	},
  /**
   * 预览图片
   */
  previewImgs: function (event) {
    //放大预览图片
    var pictureUrls = this.data.uploadedPictures
    wx.previewImage({
      current: 2, // 当前显示图片的http链接
      urls: pictureUrls // 需要预览的图片http链接列表
    })
  },
	storedData: function() {
		wx.setStorageSync("customKey", "我是中国人")
	},
	getStoredData: function() {
		var value = wx.getStorageSync("customKey")
		console.log("取出的数据：" + value)
	},
	startPaiVideo: function() {
		wx.chooseVideo({
			sourceType: ['album', 'camera'],
			maxDuration: 15,
			success: function(res) {
				console.log(res.tempFilePath)
			},
			fail: function(res) {},
			complete: function(res) {},
		})
	},
	videoPlayer: function() {
		wx.navigateTo({
			url: '../second1/second1'
		})
	},
	switchChangeAction: function(event) {
		console.log('switch1 发生 change 事件，携带值为', event.detail.value)
	},
	blockUse: function() {
		wx.navigateTo({
			url: '../second/second?flag=1',
		})
	},
	useTemplate: function() {
		wx.navigateTo({
			url: '../second/second?flag=2',
		})
	},
	wxsUse: function() {
		wx.navigateTo({
			url: '../second2/second2',
		})
	},
	layoutGridView: function() {
		wx.navigateTo({
			url: '../second/second?flag=3',
		})
	},
	beforeAndAfter: function() {
		wx.navigateTo({
			url: '../second/second?flag=4',
		})
	},
	mycenterlist: function() {
		wx.navigateTo({
			url: '../mycenter/mycenter',
		})
	},
	lunboAD: function() {
		wx.navigateTo({
			url: '../lunbo/lunbo',
		})
	},
	shishangbaoHome: function() {
		wx.navigateTo({
			url: '../ssb/home/home',
		})
	},
	shishangbaoguanzhu: function() {
		wx.navigateTo({
			url: '../ssb/guanzhu/guanzhu',
		})
	},
	shishangbaojigoulist: function() {
		wx.navigateTo({
			url: '../ssb/jigoulist/jigoulist',
		})
	},
	shishangbaojigoudetail: function() {
		wx.navigateTo({
			url: '../ssb/jigouinfo/jigouinfo',
		})
	},
	shishangbaobumendetail: function() {
		wx.navigateTo({
			url: '../ssb/bumeninfo/bumeninfo',
		})
	},
  leftSwipeDelete: function() {
    wx.navigateTo({
      url: '../leftswipedelete/leftswipedelete',
    })
  },
  videoPlay: function() {
    wx.navigateTo({
      url: '../videoplay/videoplay',
    })
  },
  openDocument: function() {
    wx.navigateTo({
      url: '../opendocument/opendocument',
    })
  },
  orderlist: function() {
    wx.navigateTo({
      url: '../orderlist/orderlist',
    })
  },
  useComponentDemo: function() {
    wx.navigateTo({
      url: '../placeholderimg/placeholderimg',
    })
  },
  textareaDemo: function() {
    wx.navigateTo({
      url: '../textarealevel/textarealevel',
    })
  },
  npmPackagerUseDemo: function () {
    wx.navigateTo({
      url: '../npmtest/npmtest',
    })
  },
  gestureJianting: function () {
    wx.navigateTo({
      url: '../gesturejianting/gesturejianting',
    })
  },
  bookreader: function () {
    wx.navigateTo({
      url: '../bookreader/bookreader',
    })
  },
  cssDonghua: function () {
    wx.navigateTo({
      url: '../cssdonghua/cssdonghua',
    })
  },
  bookreaderPaging: function () {
    wx.navigateTo({
      url: '../readerpageing/readerpageing',
    })
  },
  guagualepage: function () {
    wx.navigateTo({
      url: '../guaguale/guaguale',
    })
  },
  dazhuanpanpage: function () {
    wx.navigateTo({
      url: '../dazhuanpan/dazhuanpan',
    })
  },
  dazhuanpannewpage: function () {
    wx.navigateTo({
      url: '../zp/zp',
    })
  },
  dazhuanpan002page: function () {
    wx.navigateTo({
      url: '../dazhuanpan002/dazhuanpan002',
    })
  },
  audioplayanimation: function () {
    wx.navigateTo({
      url: '../audioplayanimation/audioplayanimation',
    })
  },
  starpingji: function () {
    wx.navigateTo({
      url: '../starpingjia/starpingjia',
    })
  },
  dianziqianming: function () {
    wx.navigateTo({
      url: '../dianziqianming/dianziqianming',
    })
  },
  gundonggonggao: function () {
    wx.navigateTo({
      url: '../gundonggonggao/gundonggonggao',
    })
  },
  maobolixiaoguo: function () {
    wx.navigateTo({
      url: '../maobolixiaoguo/maobolixiaoguo',
    })
  },
  scrollviewRefresh1: function () {
    wx.navigateTo({
      url: '../scrollviewrefresh/scrollviewrefresh',
    })
  },
  scrollviewRefresh2: function () {
    wx.navigateTo({
      url: '../scrollviewrefresh2/scrollviewrefresh2',
    })
  },
  scrollviewRefresh3: function () {
    wx.navigateTo({
      url: '../scrollviewrefresh3/scrollviewrefresh3',
    })
  },
  scrollviewRefresh4: function () {
    wx.navigateTo({
      url: '../scrollviewrefresh4/scrollviewrefresh4',
    })
  },
  scrollviewRefresh5: function () {
    wx.navigateTo({
      url: '../scrollviewrefresh5/scrollviewrefresh5',
    })
  },
  scrollviewRefresh6: function () {
    wx.navigateTo({
      url: '../scrollviewrefresh6/scrollviewrefresh6',
    })
	},
	inputdemo: function () {
    wx.navigateTo({
      url: '../inputdemo/inputdemo',
    })
	},
	testPromise: function () {
    var onePromise = new Promise((resolve, reject) => {
			setTimeout(resolve, 3000, 'done')
		})

		onePromise.then((value) => {
			console.log("成功 " + value)
		}, (error) => {
			console.log("失败")
		});
	},
	lunboWithMargin: function () {
    wx.navigateTo({
      url: '../lunbowithmargin/lunbowithmargin',
    })
	},






  onLoad: function () {
		console.log("*******index页面---onLoad********")
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else if (this.data.canIUse){
      // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
				console.log("获取的用户信息如下：\n %o", res.userInfo)
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }
  },
	onReady: function() {
		console.log("*******index页面---onReady********")
		let arr = [,,,]
		console.log(arr)
	},
	onShow: function () {
		console.log("*******index页面---onShow********")
	},
	onHide: function () {
		console.log("*******index页面---onHide********")
	},
	onUnload: function () {
		console.log("*******index页面---onUnload********")
	},
	onPullDownRefresh: function() {
		console.log("*******index页面---onPullDownRefresh********")
		wx.stopPullDownRefresh() //停止当前页面的下拉刷新
	},
	onShareAppMessage: function (res) {
		console.log("******* index页面-- - onShareAppMessage ********")
		if (res.from === 'button') {
			// 来自页面内转发按钮
			console.log(res.target)
		}
		return {
			title: '自定义转发标题',
      imageUrl: "../../images/testavatar02.jpg",
			path: 'pages/second1/second1'
		}
	},

  getUserInfo: function(e) {
		console.log("*******index页面---getUserInfo******")
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  }
})
